package com.yanze.schoolinformation.adapter.rv;

import android.app.Activity;
import android.support.annotation.NonNull;
import android.view.ViewGroup;

import com.yanze.schoolinformation.R;
import com.yanze.schoolinformation.base.baseadapter.BaseRecyclerViewAdapter;
import com.yanze.schoolinformation.base.baseadapter.BaseRecyclerViewHolder;
import com.yanze.schoolinformation.databinding.ItemOneMovieBinding;
import com.yanze.schoolinformation.model.bean.moviechild.SubjectsBean;
import com.yanze.schoolinformation.view.information.movie.MovieDetailActivity;
import com.yanze.schoolinformation.viewModule.movie.OneItemClickCallback;
import com.nineoldandroids.view.ViewHelper;
import com.nineoldandroids.view.ViewPropertyAnimator;
import android.view.animation.OvershootInterpolator;

/**
 * Created by MrZheng on 2018/4/26.
 */

public class HotMovieAdapter extends BaseRecyclerViewAdapter<SubjectsBean> {

    private Activity activity;

    public HotMovieAdapter(Activity activity) {
        this.activity = activity;
    }

    @NonNull
    @Override
    public BaseRecyclerViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder(parent, R.layout.item_one_movie);
    }

    private class ViewHolder extends BaseRecyclerViewHolder<SubjectsBean, ItemOneMovieBinding> {
        public ViewHolder(ViewGroup viewGroup, int layoutId) {
            super(viewGroup, layoutId);
        }

        @Override
        public void onBindViewHolder(final SubjectsBean bean, int position) {
            if (bean != null) {
                binding.setSubjectsBean(bean);
                binding.setCallback(new OneItemClickCallback() {
                    @Override
                    public void onClick(SubjectsBean subjectsBean) {
                        MovieDetailActivity.start(activity, bean, binding.ivOnePhoto);
                    }
                });
                binding.executePendingBindings();

                ViewHelper.setScaleX(itemView,0.8f);
                ViewHelper.setScaleY(itemView,0.8f);
                ViewPropertyAnimator.animate(itemView).scaleX(1).setDuration(350).setInterpolator(new OvershootInterpolator()).start();
                ViewPropertyAnimator.animate(itemView).scaleY(1).setDuration(350).setInterpolator(new OvershootInterpolator()).start();
            }
        }
    }
}
